//
//  HomePageViewController.m
//  ServerDemo
//
//  Created by rp.wang on 2018/1/10.
//  Copyright © 2018年 兰州北科维拓科技股份有限公司. All rights reserved.
//

#import "HomePageViewController.h"
#import "Masonry.h"

static NSString * const HomeTableCellID = @"HomeTableCellID";

@interface HomePageViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (strong, nonatomic) UITableView *tableView;

@end

@implementation HomePageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = @"Home Page";
    
    [self tableView];
    //防止Block循环引用
    __weak typeof (self) weakSelf = self;
    
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        //top left bottom right
        make.edges.equalTo(weakSelf.view).with.insets(UIEdgeInsetsMake(8, 0, 0, 0));
        
    }];
    //除去多余的分割线
    [[PublicViModel sharedInstance] setExtraCellLineHidden:_tableView];
    ///top left bottom right
    _tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
    
    _tableView.showsVerticalScrollIndicator = NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -  UItableview
-(UITableView *)tableView
{
    if(!_tableView)
    {
        _tableView = [[UITableView alloc]init];
        
        _tableView.delegate = self;
        
        _tableView.dataSource = self;
        
        _tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
        
        [self.view addSubview:_tableView];
    }
    
    return _tableView;
}


#pragma mark - UITableView
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSArray *lsList = @[@"Add Data",@"Delete Data",@"change the data",@"Find data by ID",@"Find data by criteria"];
    
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:HomeTableCellID];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    cell.textLabel.text = lsList[indexPath.row];
    cell.textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:21];
    cell.textLabel.textAlignment = NSTextAlignmentCenter;
   
    return cell;
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 55.f;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == 0)
    {
         BaseViewController * AddDataPage =  [[NSClassFromString(@"AddDataViewController") alloc]init];
        [self.navigationController pushViewController:AddDataPage animated:YES];
    }
}

@end
